package husc.se.ndung.soiphubaimobile;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import husc.se.ndung.soiphubaimobile.Entity.ChiTietMay;

/**
 * Created by DungNguyen on 5/14/2015.
 */
public class AdapterChiTietMay extends ArrayAdapter<ChiTietMay> {
    List<ChiTietMay> lsChiTietMay;
    int resource;
    Activity context;

    public AdapterChiTietMay(Activity context, int resource, List<ChiTietMay> objects) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.lsChiTietMay = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = context.getLayoutInflater().inflate(resource, null);
        LinearLayout wrapper = (LinearLayout) convertView.findViewById(R.id.wrapperChiTiet);
        wrapper.setBackgroundColor(Integer.parseInt(lsChiTietMay.get(position).GetMau()));
        TextView lbNameChiTietMay = (TextView) convertView.findViewById(R.id.lbNameChiTietMay);
        TextView lbNameNhiemVuBaoTri = (TextView) convertView.findViewById(R.id.lbNameNhiemVuBaoTri);
        TextView lbThongTin = (TextView) convertView.findViewById(R.id.lbNameThongTinChung);
        TextView lbQuaHan = (TextView) convertView.findViewById(R.id.lbHanBaoTri);
        TextView lbNgayBaoTri= (TextView) convertView.findViewById(R.id.lbNgayBaoTri);
        if (lbNameChiTietMay!=null &&
                lbNameNhiemVuBaoTri!=null &&
                lbThongTin!=null &&
                lbQuaHan!=null &&
                lbNgayBaoTri !=null)
        {
            lbNameChiTietMay.setText(lsChiTietMay.get(position).GetTenChiTietMay());
            lbNameNhiemVuBaoTri.setText(lsChiTietMay.get(position).GetTenNhiemVuBaoTri());

            lbThongTin.setText(lsChiTietMay.get(position).GetThongTinChung());
            lbQuaHan.setText(lsChiTietMay.get(position).GetHanBaoTri());
            lbNgayBaoTri.setText(lsChiTietMay.get(position).GetNgayBaoTri());
        }
        return convertView;
    }
}
